package com.ruoyi.platform.system.file.service;

import com.ruoyi.base.exception.SysException;
import com.ruoyi.base.utils.oss.OssUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 文件上传
 *
 * @author lcf
 */
@Service
public class FileUploadService {
    /**
     * 多图片上传
     */
    public List<String> uploadImg(String bucket, MultipartFile[] files, boolean isCompress) {
        return Arrays.stream(files).map(x -> uploadImg(bucket, x, isCompress)).collect(Collectors.toList());
    }

    /**
     * 图片上传
     */
    public String uploadImg(String bucket, MultipartFile file, boolean isCompress) {
        return OssUtils.uploadImg(bucket, file, isCompress);
    }

    /**
     * 多文件上传
     */
    public List<String> uploadFile(String bucket, MultipartFile[] files) {
        return Arrays.stream(files).map(x -> uploadFile(bucket, x)).collect(Collectors.toList());
    }

    /**
     * 文件上传
     */
    public String uploadFile(String bucket, MultipartFile file) {
        return OssUtils.uploadFile(bucket, file);
    }
}
